{{- if .Values.egress.enabled }}
{{- if eq .Values.controlPlane.mode "global" }}
{{ fail "You shouldn't run zoneEgress when running the CP in global" }}
{{- end }}
{{- end }}
{{- if and .Values.egress.enabled .Values.egress.service.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "kuma.egress.serviceName" . }}
  namespace: {{ .Release.Namespace }}
  labels: {{ include "kuma.egressLabels" . | nindent 4 }}
  annotations:
    {{- range $key, $value := .Values.egress.service.annotations }}
      {{ $key }}: {{ $value | quote }}
    {{- end }}
spec:
  type: {{ .Values.egress.service.type }}
  {{- if .Values.egress.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.egress.service.loadBalancerIP }}
  {{- end }}
  ports:
    - port: {{ .Values.egress.service.port }}
      protocol: TCP
      targetPort: 10002
    {{- if and (eq .Values.egress.service.type "NodePort")  .Values.egress.service.nodePort }}
      nodePort: {{ .Values.egress.service.nodePort }}
    {{- end }}
  selector:
    app: {{ include "kuma.name" . }}-egress
  {{- include "kuma.selectorLabels" . | nindent 4 }}
{{- end }}
